<?php
  include_once dirname(__FILE__)."/../../database/database.class.php";
  
  if((isset($_GET['new_deck']) || isset($_GET['remove_deck'])) && isset($_COOKIE["MGTDatabase_user"]) && is_numeric($_COOKIE["MGTDatabase_user"]))
  {
    if(isset($_GET['new_deck']))
    {
      $result = $db->addDeck($_GET['new_deck'], $_COOKIE["MGTDatabase_user"]);
      if(is_string($result))
      {
        echo '<p>'.$result.'</p>';
      }
    }
    if(isset($_GET['remove_deck']) && is_numeric($_GET['remove_deck']))
    {
      $db->removeDeck($_GET['remove_deck']);
    }
  }
?>

<center><table class="decks_overview" cellspacing="0px">
  <tr>
    <th>Name</th>
    <th>Unique</th>
    <th>Total</th>
    <th></th>
  </tr>
<?php

  $even = FALSE;

  if(!isset($_COOKIE["MGTDatabase_user"]) || !is_numeric($_COOKIE["MGTDatabase_user"]))
  {
    $_COOKIE["MGTDatabase_user"] = 0;
  }

  foreach($db->getDecks($_COOKIE["MGTDatabase_user"]) as $deck)
  {
    $deck = new Deck($deck->ID);

    $even=!$even;

    echo "<tr class=\"";
    if($even)
    {
      echo "even_row";
    }
    else
    {
      echo "uneven_row";
    }
    echo '">
      <td class="decks_name"><a href="?deckId='.$deck->getID().'">'.$deck->getName().'</a></td>
      <td>'.$deck->getUniqueSize().'</td>
      <td>'.$deck->getSize().'</td>
      <td><a href="?remove_deck='.$deck->getID().'">X</a></td>
     </tr>';
  }
?>
</table></center>

<form><input type="text" name="new_deck"><input type="submit"></form>
